﻿Imports Microsoft.VisualBasic
Imports System

Namespace $RootNamespace$

    ' "$IState$" 
    Friend Interface $IState$
        Sub $Handle$(ByVal context As $Context$)
        ReadOnly Property ThisState() As String

    End Interface


    ' "$Context$" 
    Friend Class $Context$
        Shared Sub Test()
            ' Setup context in a $IState$ 
            Dim c As New $Context$(New $ConcreteStateA$())

            ' Client requests, which toggles $RootNamespace$ 
            c.Request()
            c.Request()
            c.Request()

        End Sub

        ' Constructor 
		Public Sub New(ByVal $RootNamespace$ As $IState$)
			Me.CurrentState = $RootNamespace$
        End Sub

        ' Property 
        Private privateCurrentState As $IState$
        Public Property CurrentState() As $IState$
            Get
                Return privateCurrentState
            End Get
            Set(ByVal value As $IState$)
                privateCurrentState = value
            End Set
        End Property

        Public Sub Request()
            Console.WriteLine("Request on " & CurrentState.ThisState)
            CurrentState.$Handle$(Me)
        End Sub
    End Class


    ' "$ConcreteStateA$" 
    Friend Class $ConcreteStateA$
        Implements $IState$
        Public Sub $Handle$(ByVal context As $Context$) Implements $IState$.$Handle$
            context.CurrentState = New $ConcreteStateB$()
        End Sub

        Public ReadOnly Property ThisState() As String Implements $IState$.ThisState
            Get
                Return "$ConcreteStateA$"
            End Get
        End Property
    End Class

    ' "$ConcreteStateB$" 
    Friend Class $ConcreteStateB$
        Implements $IState$
        Public Sub $Handle$(ByVal context As $Context$) Implements $IState$.$Handle$
            context.CurrentState = New $ConcreteStateC$()
        End Sub
        Public ReadOnly Property ThisState() As String Implements $IState$.ThisState
            Get
                Return "$ConcreteStateB$"
            End Get
        End Property
    End Class

    ' "$ConcreteStateC$" 
    Friend Class $ConcreteStateC$
        Implements $IState$
        Public Sub $Handle$(ByVal context As $Context$) Implements $IState$.$Handle$
            context.CurrentState = New $ConcreteStateA$()
        End Sub
        Public ReadOnly Property ThisState() As String Implements $IState$.ThisState
            Get
                Return "$ConcreteStateC$"
            End Get
        End Property
    End Class

End Namespace